/**
 * CRM模块路由配置
 */

import type { RouteRecordRaw } from 'vue-router'

const crmRoutes: RouteRecordRaw[] = [
  {
    path: 'crm',
    name: 'Crm',
    redirect: '/crm/dashboard', // 添加默认重定向
    component: () => import('@/views/crm/CrmLayout.vue'),
    meta: {
      title: 'CRM管理',
      requiresAuth: true,
    },
    children: [
      {
        path: 'dashboard',
        name: 'CrmDashboard',
        component: () => import('@/views/crm/CrmDashboard.vue'),
        meta: {
          title: 'CRM概览',
        },
      },
      {
        path: 'opportunity',
        name: 'OpportunityList',
        component: () => import('@/views/crm/opportunity/OpportunityList.vue'),
        meta: {
          title: '销售机会',
        },
      },
      {
        path: 'opportunity/:id',
        name: 'OpportunityDetail',
        component: () => import('@/views/crm/opportunity/OpportunityDetail.vue'),
        meta: {
          title: '销售机会详情',
        },
        props: true,
      },
      {
        path: 'customers',
        name: 'CrmCustomerList',
        component: () => import('@/views/crm/CustomerList.vue'),
        meta: {
          title: '客户管理',
        },
      },
      {
        path: 'followups',
        name: 'FollowupList',
        component: () => import('@/views/crm/FollowupList.vue'),
        meta: {
          title: '跟进记录',
        },
      },
      {
        path: 'order',
        name: 'OrderList',
        component: () => import('@/views/crm/order/OrderList.vue'),
        meta: {
          title: '业务订单',
        },
      },
      {
        path: 'orders',
        name: 'OrdersList',
        component: () => import('@/views/crm/order/OrderList.vue'),
        meta: {
          title: '业务订单',
        },
      },
      {
        path: 'order/list',
        name: 'CrmOrderList',
        component: () => import('@/views/crm/order/OrderList.vue'),
        meta: {
          title: '业务订单',
        },
      },
      {
        path: 'order/create',
        name: 'OrderCreate',
        component: () => import('@/views/crm/order/OrderCreate.vue'),
        meta: {
          title: '创建订单',
        },
      },
      {
        path: 'finance',
        name: 'FinanceList',
        component: () => import('@/views/crm/finance/FinanceList.vue'),
        meta: {
          title: '财务审核',
        },
      },
      {
        path: 'reviews',
        name: 'Reviews',
        redirect: '/crm/reviews/customer',
        meta: {
          title: '审核管理',
        },
      },
      {
        path: 'reviews/customer',
        name: 'CustomerReview',
        component: () => import('@/views/crm/CustomerReviewPage.vue'),
        meta: {
          title: '客户审核',
        },
      },
      {
        path: 'reviews/order',
        name: 'OrderReview',
        component: () => import('@/views/crm/OrderReviewPage.vue'),
        meta: {
          title: '订单审核',
        },
      },
      {
        path: 'contract',
        name: 'ContractReview',
        component: () => import('@/views/crm/ContractReviewPage.vue'),
        meta: {
          title: '合同审核',
        },
      },
      {
        path: 'cooperation',
        name: 'CooperationList',
        component: () => import('@/views/crm/CustomerList.vue'),
        meta: {
          title: '已合作客户',
        },
        props: {
          isCooperation: true,
        },
      },
      {
        path: 'public',
        name: 'PublicCustomerList',
        component: () => import('@/views/crm/CustomerList.vue'),
        meta: {
          title: '公海客户',
        },
        props: {
          isPublic: true,
        },
      },
      {
        path: 'orders/:id',
        name: 'OrderDetail',
        component: () => import('@/views/crm/components/OrderDetail.vue'),
        meta: {
          title: '订单详情',
        },
        props: true,
      },
      // 客户管理操作路由
      {
        path: 'customers/view',
        name: 'CustomerViewAction',
        redirect: '/crm/customers',
        meta: {
          title: '客户查看',
        },
      },
      {
        path: 'customers/add',
        name: 'CustomerAddAction',
        redirect: '/crm/customers',
        meta: {
          title: '客户添加',
        },
      },
      {
        path: 'customers/edit',
        name: 'CustomerEditAction',
        redirect: '/crm/customers',
        meta: {
          title: '客户编辑',
        },
      },
      {
        path: 'customers/delete',
        name: 'CustomerDeleteAction',
        redirect: '/crm/customers',
        meta: {
          title: '客户删除',
        },
      },
      // 跟进记录操作路由
      {
        path: 'followups/view',
        name: 'FollowupViewAction',
        redirect: '/crm/followups',
        meta: {
          title: '跟进记录查看',
        },
      },
      {
        path: 'followups/add',
        name: 'FollowupAddAction',
        redirect: '/crm/followups',
        meta: {
          title: '跟进记录添加',
        },
      },
      {
        path: 'followups/edit',
        name: 'FollowupEditAction',
        redirect: '/crm/followups',
        meta: {
          title: '跟进记录编辑',
        },
      },
      {
        path: 'followups/delete',
        name: 'FollowupDeleteAction',
        redirect: '/crm/followups',
        meta: {
          title: '跟进记录删除',
        },
      },
    ],
  },
]

// 直接导出修复后的路由
export default crmRoutes
